<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:gml="http://www.opengis.net/gml" 
	xmlns:ogr="http://ogr.maptools.org/"
	xmlns:ramon_geo="http://ec.europa.eu/eurostat/ramon/ontologies/geographic.rdf#" 
	xmlns:nuts="http://nuts.geovocab.org/id/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
	
<xsl:output method="xml" indent="yes" />
	
<xsl:template match="/ogr:FeatureCollection">
	
	<xsl:result-document href="id/index.rdf">
		<rdf:RDF>
			<rdf:Description rdf:about="http://nuts.geovocab.org/id/index">
				<rdfs:seeAlso rdf:resource="http://nuts.geovocab.org/id/nuts0"/>
				<rdfs:seeAlso rdf:resource="http://nuts.geovocab.org/id/nuts1"/>
				<rdfs:seeAlso rdf:resource="http://nuts.geovocab.org/id/nuts2"/>
				<rdfs:seeAlso rdf:resource="http://nuts.geovocab.org/id/nuts3"/>
			</rdf:Description>
		</rdf:RDF>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts0.rdf">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="0"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts1.rdf">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="1"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts2.rdf">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="2"/>
		</xsl:call-template>
	</xsl:result-document>
	
	<xsl:result-document href="id/nuts3.rdf">
		<xsl:call-template name="nuts_index">
			<xsl:with-param name="level" select="3"/>
		</xsl:call-template>
	</xsl:result-document>
	
</xsl:template>

<xsl:template name="nuts_index">
	<xsl:param name="level" />
	
	<rdf:RDF>
		<rdf:Description rdf:about="{concat('http://nuts.geovocab.org/id/nuts',$level)}">
			<xsl:for-each select='gml:featureMember/ogr:NUTS_RG_60M_2006[ogr:STAT_LEVL_=$level]' >
				<rdfs:seeAlso rdf:resource="{concat('http://nuts.geovocab.org/id/',ogr:NUTS_ID)}"/>
			</xsl:for-each>	
		</rdf:Description>
	</rdf:RDF>
</xsl:template>

</xsl:stylesheet>